﻿@{
    Bundle("jquery_validate");
    Bundle("ckeditor");
}
           
<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('@ID("#form")').validate({
            rules: {
                from: {
                    required: true
                },
                to: {
                    required: true
                },
                subject: {
                    required: true
                },
                sendAttemptCount: {
                    required: true,
                    digits: true
                }
            }
        });
        jQuery('@ID("#txt_text")').ckeditor();
        jQuery.ajax({
            type: 'post',
            url: '@Url.Action(Loc.Act("Senders").Ctrl("Message"))',
            dataType: 'json',
            success: function (rsp) {
                var ddl = jQuery('@ID("#ddl_sender")');
                ddl.empty();
                jQuery.each(rsp, function (k, v) {
                    ddl.append('<option value=' + v.id + '>' + v.value + '</option>');
                });
                ddl.val('@JDM.Guid(Model.SenderID)');
                ddl.change();
            }
        });
    });
</script>
<form id="@ID("form")" action="@Url.Action(Loc.Act("Update").Ctrl("Message"))" method="post">
    <input type="hidden" name="flags" value="None" />
    <table>
        <tr>
            <td>
                <label>#</label>
            </td>
            <td>
                <input type="text" readonly name="id" value="@JDM.Int32(Model.EntityID)" />
            </td>
        </tr>
        <tr>
            <td>
                <label>&#10001;</label>
            </td>
            <td>
                <input type="text" readonly value="@Svc.DateTime((DateTime)JDM.DateTime(Model.CreatedOn))" />
            </td>
        </tr>
        <tr>
            <td>
                <label>&#10002;</label>
            </td>
            <td>
                <input type="text" readonly value="@Svc.DateTime((DateTime)JDM.DateTime(Model.UpdatedOn))" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("SentOn"))</label>
            </td>
            <td>
                <input type="text" readonly value="@(Model.SentOn != null ? Svc.DateTime((DateTime)JDM.DateTime(Model.SentOn)) : String.Empty)" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("SendAttemptCount"))</label>
            </td>
            <td>
                <input type="text" name="sendAttemptCount" value="@JDM.Int32(Model.SendAttemptCount)" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Sender"))</label>
            </td>
            <td>
                <select id="@ID("ddl_sender")"></select>
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("From"))</label>
            </td>
            <td>
                <input type="text" name="from" value="@JDM.String(Model.From)" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("To"))</label>
            </td>
            <td>
                <input type="text" name="to" value="@JDM.String(Model.To)" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("BccTo"))</label>
            </td>
            <td>
                <input type="text" name="bccTo" value="@JDM.String(Model.BccTo)" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("ReplyTo"))</label>
            </td>
            <td>
                <input type="text" name="replyTo" value="@JDM.String(Model.ReplyTo)" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Subject"))</label>
            </td>
            <td>
                <input type="text" name="subject" value="@JDM.String(Model.Subject)" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Text"))</label>
            </td>
            <td>
                <textarea id="@ID("txt_text")" name="text">@Html.Raw(JDM.String(Model.Text))</textarea>
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.In("API").Of("Enum").Of("MessageFlags").Name("Active"))</label>
            </td>
            <td>
                <input type="checkbox" name="flags" value="Active" @(JDM.HasFlags(Model.Flags, "Active") ? "checked" : String.Empty) />
            </td>
        </tr>
    </table>
    <ul class="bar toolbar">
        <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
    </ul>
</form>